package org.quipu.utils;

import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedList;
import org.quipu.domain.UniqueEntity;
import org.quipu.domain.Tag;

public class DaoHelper {

    public static class RatingComparator implements Comparator<Tag> {

        public int compare(Tag tag1, Tag tag2) {
            int size1 = tag1.getTransactionMapping().size();
            int size2 = tag2.getTransactionMapping().size();
            if(size1 > size2)
                return 1;
            else if(size1 < size2)
                return -1;
            else
                return 0;
        }
    }

    public static Collection<Long> getIds(Collection<? extends UniqueEntity> entities) {
        Collection<Long> ids = new LinkedList<Long>();
        if(entities != null) {
            for(UniqueEntity entity: entities)
                ids.add(entity.getId());
        }
        return ids;
    }
}
